import { type JSXElement, createContext, useContext } from "solid-js";

const DisabledContext = createContext<boolean>(false);

export interface DisabledContextProps {
  disabled?: boolean;
  children?: JSXElement;
}

export const DisabledContextProvider = (props: DisabledContextProps) => {
  const originDisabled = useContext(DisabledContext);

  return (
    <DisabledContext.Provider value={props.disabled ?? originDisabled}>
      {props.children}
    </DisabledContext.Provider>
  );
};
